Exploratory Programming for the Arts and Humanities by Nick Montfort

Exploratory Programming for the Arts and Humanities by Nick Montfort

Author:Nick Montfort [Montfort, Nick]
Language: eng
Format: epub
Tags: python; anaconda; computing;
Publisher: MIT Press
Published: 2021-04-28T00:00:00+00:00


def tax(subtotal):

"Return the amount of detective tax due on the given subtotal."

return subtotal * 0.08875↵

Now see what happens when you ask for help regarding your own function:

help(tax)↵

Including a docstring can be extremely helpful. You could figure out what the function is doing by going through the (one line of) code, but there is nothing else in the tax() function that would explain why it was written—that this function computes the tax on detective services. This is why comments, generally, are useful. In Python, the most important comment-like text you should write is the docstring that briefly explains the operation and purpose of each function you develop.

You also may want to know, for a specific Python object, what methods and attributes that object has. For instance, what can we do with a list? To find this out, we can ask for the directory of a list using the dir() function. Any list will do; let’s use the empty list:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.